//concerned_master_list
exports.concerned_master_list = function (req, res) {

    var restfulParams = req.routeInfo.restfulParams;
    //最终结果
    var resultData = {};

    var limit = restfulParams.limit == undefined ? config.publicConfig.LIMIT : restfulParams.limit;

    var skip = restfulParams.skip == undefined ? 0 : restfulParams.skip;
    //任务流创建
    async.waterfall([

            function (cb) {
                R.SEND_HTTP(
                    req,
                    {
                        url: CORE_APIConfig.coreAPI.searchMasterConcern + "/mc_uid/" + restfulParams.u_id+"/sort_order/mc_create_time-desc/skip/" + skip + "/limit/" + limit,
                        method: 'POST',
                        data: {
                            fields: ["mc_master_id", "mc_type"].join(",")
                        }
                    },
                    function (err, data) {
                        //console.log(data);
                        //判断是否有错误信息
                        if (err) {
                            return cb(err, data);
                        }
                        resultData.masterData = data.data;
                        cb();
                    }
                );

            },
        function (cb) {

            var masterData = resultData.masterData;

            var tasks = [];

            masterData.forEach(function (item, i) {
                tasks.push(function (cb) {
                    if(item.mc_type==1){

                        R.SEND_HTTP(
                            req,
                            {
                                url: CORE_APIConfig.coreAPI.searchOrganization + "/o_id/" + item.mc_master_id,
                                method: 'POST',
                                data: {
                                    fields: ["o_name", "o_desc", "o_logo"].join(",")
                                }
                            },
                            function (err, data) {

                                //判断是否有错误信息
                                if (err) {
                                    return cb(err, data);
                                }

                                var organizationInfo = data.data[0];

                                item.nickname = organizationInfo.o_name;

                                item.desc = organizationInfo.o_desc;

                                item.header_url = organizationInfo.o_logo;

                                cb();
                            }
                        );
                    }else{
                        R.SEND_HTTP(
                            req,
                            {
                                url: CORE_APIConfig.coreAPI.search_forum_master + "/m_uid/" + item.mc_master_id,
                                method: 'POST',
                                data: {
                                    fields: ["m_nickname", "m_sign", "u_header_url"].join(",")
                                }
                            },
                            function (err, data) {

                                //判断是否有错误信息
                                if (err) {
                                    return cb(err, data);
                                }

                                var masterInfo = data.data[0];

                                item.nickname = masterInfo.m_nickname;

                                item.desc = masterInfo.m_sign;

                                item.header_url = masterInfo.u_header_url;

                                cb();
                            }
                        );
                    }
                })
            });
            async.waterfall(tasks, cb);
        },
        ], function (err, result) {

            //返回最终拼接结果
            RES.response(res, true, resultData);

        }
    );

};